import java.util.ArrayList;
import java.util.List;

public class TableHeader
{
	private String title = "";

	private List<TableHeader> children = new ArrayList<>();

	public String getTitle()
	{
		return title;
	}

	public void setTitle(String title)
	{
		this.title = title;
	}

	public List<TableHeader> getChildren()
	{
		return children;
	}

	public void setChildren(List<TableHeader> children)
	{
		this.children = children;
	}

	public TableHeader(String title, List<TableHeader> children)
	{
		super();
		this.title = title;
		this.children = children;
	}

	public TableHeader(String title)
	{
		super();
		this.title = title;
	}

	private static List<String> getHeaders(TableHeader tableHeader, List<List<String>> lists, List<String> list)
	{
		list.add(tableHeader.getTitle());
		if (tableHeader.getChildren() != null && tableHeader.getChildren().size() > 0)
		{
			tableHeader.getChildren().forEach(item -> {
				List<String> newlist = new ArrayList<>(list);
				getHeaders(item, lists, newlist);
			});
		}
		else
		{
			lists.add(list);
		}
		return list;
	}

	public static List<List<String>> getHeaders(List<TableHeader> list)
	{
		List<List<String>> lists = new ArrayList<>();
		list.forEach(item -> {
			getHeaders(item, lists, new ArrayList<>());
		});
		return lists;
	}

	public static void main(String[] args)
	{
		List<TableHeader> list = new ArrayList<>();

		// 目录1
		TableHeader t1 = new TableHeader("目录1");
		List<TableHeader> children = new ArrayList<>();
		TableHeader t11 = new TableHeader("1-1");
		children.add(t11);
		List<TableHeader> t11children = new ArrayList<>();
		t11children.add(new TableHeader("1-1-1"));
		t11children.add(new TableHeader("1-1-2"));
		t11.setChildren(t11children);

		children.add(new TableHeader("1-2"));
		children.add(new TableHeader("1-3"));
		t1.setChildren(children);
		list.add(t1);

		// 目录2
		TableHeader t2 = new TableHeader("目录2");
		List<TableHeader> t2children = new ArrayList<>();
		t2.setChildren(t2children);
		t2children.add(new TableHeader("2-1"));

		TableHeader t22 = new TableHeader("2-2");
		List<TableHeader> t22children = new ArrayList<>();
		t22.setChildren(t22children);
		t22children.add(new TableHeader("2-2-1"));
		t22children.add(new TableHeader("2-2-2"));
		TableHeader t223 = new TableHeader("2-2-3");
		List<TableHeader> t223children = new ArrayList<>();
		t223children.add(new TableHeader("2-2-3-1"));
		t223children.add(new TableHeader("2-2-3-2"));
		t223.setChildren(t223children);
		t22children.add(t223);

		t2children.add(t22);
		t2children.add(new TableHeader("2-3"));
		list.add(t2);

		List<List<String>> lists = TableHeader.getHeaders(list);

		System.out.println(lists);
	}
}
